package remoteControl.panel;

import java.util.UUID;

import android.app.Activity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.TextView;

public class RemoteControlActivity extends Activity 
{
 int modoRemotoControl = 0;
 String btAdress = "00:06:66:07:AC:2A";
 final UUID MY_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");
 BluetoothAdapter btAdapter;
 BluetoothSocket btSocket;
 public BluetoothDevice device;
 boolean conectado = false;
 
 Button btnRemoteControl;
 Button btnGetGPS;
 Button btnConfigure;
 Spinner sp;
 TextView tv;
 
 @Override
 public void onCreate(Bundle savedInstanceState) 
 {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  Bundle extras = getIntent().getExtras();
  if( extras != null)
  { 
   btAdress = extras.getString("MAC").toString();
  }
  
  // Elementos graficos
  
  sp = (Spinner) findViewById(R.id.spinner1); 
  btnRemoteControl = (Button) findViewById(R.id.button1);
  btnGetGPS = (Button) findViewById(R.id.button2);
  btnConfigure = (Button) findViewById(R.id.button3);
  tv = (TextView) findViewById(R.id.textView1);
  tv.setText("Dispositivo : " + btAdress);
  


 
  // ElementoGrafico -> Spinner
  ArrayAdapter<?> adapter = ArrayAdapter.createFromResource(this, R.array.versiones, android.R.layout.simple_spinner_item);
  adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  sp.setAdapter(adapter);
  sp.setOnItemSelectedListener(new OnItemSelectedListener() 
  {
   public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) 
   {
    modoRemotoControl = position;
   }
   public void onNothingSelected(AdapterView<?> parentView) 
   {    	
   }
  });    
 
 //Listening to button event
 btnRemoteControl.setOnClickListener(new View.OnClickListener() 
 {
  public void onClick(View arg0) 
  {

   if(  modoRemotoControl == 0)
   {
 	   Intent nextScreen = new Intent(getApplicationContext(), ControlManualBotones.class);
 	   startActivity(nextScreen);
   }
   else
   {
 	   Intent nextScreen = new Intent(getApplicationContext(), ControlManualSensores.class);
 	   startActivity(nextScreen);
   }		
  }		
 });
 
 //Listening to button event
 btnGetGPS.setOnClickListener(new View.OnClickListener() 
 {
  public void onClick(View arg0) 
  {
 	   Intent nextScreen = new Intent(getApplicationContext(), ObtenerDatosGPS.class);
 	   startActivity(nextScreen);
  }	
 });
 
 btnConfigure.setOnClickListener(new View.OnClickListener()
 {
	  public void onClick(View arg0) 
	  {
	 	   Intent nextScreen = new Intent(getApplicationContext(), ConfiguracionAPP.class);
	 	  nextScreen.putExtra("MAC",btAdress.toString());
	 	   startActivity(nextScreen);
	  }	
	 });
 }
 


	

 
 
}